<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将本地时间日期格式化为整数</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.gmstrftime.html">gmstrftime</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.localtime.html">localtime</a></div>
 <div class="up"><a href="ref.datetime.html">Date/Time 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.idate" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">idate</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">idate</span> &mdash; <span class="dc-title">将本地时间日期格式化为整数</span></p>

 </div>
 <div class="refsect1 unknown-unknown-unknown-unknown-examplew" id="refsect1-function.idate-unknown-unknown-unknown-unknown-examplew">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>idate</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timestamp</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   根据给定的格式字符对 <em><code class="parameter">timestamp</code></em>
   格式化并返回数字结果。<em><code class="parameter">timestamp</code></em>
   为可选项，默认值为本地当前时间，即 <span class="function"><a href="function.time.html" class="function">time()</a></span> 的值。
  </p>
  <p class="para">
   和 <span class="function"><a href="function.date.html" class="function">date()</a></span> 不同，<span class="function"><strong>idate()</strong></span>
   只接受一个字符作为 <em><code class="parameter">format</code></em> 参数。
  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong><em><code class="parameter">format</code></em> 参数可识别以下字符</strong></caption>
    
     <thead>
      <tr>
       <th><em><code class="parameter">format</code></em> 字符</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><em>B</em></td>
       <td>Swatch Beat/Internet Time</td>
      </tr>

      <tr>
       <td><em>d</em></td>
       <td>月份中的第几天</td>
      </tr>

      <tr>
       <td><em>h</em></td>
       <td>小时（12 小时格式）</td>
      </tr>

      <tr>
       <td><em>H</em></td>
       <td>小时（24 小时格式）</td>
      </tr>

      <tr>
       <td><em>i</em></td>
       <td>分钟</td>
      </tr>

      <tr>
       <td><em>I</em></td>
       <td>如果启用夏时制则返回 <em>1</em>，否则返回 <em>0</em></td>
      </tr>

      <tr>
       <td><em>L</em></td>
       <td>如果是闰年则返回 <em>1</em>，否则返回 <em>0</em></td>
      </tr>

      <tr>
       <td><em>m</em></td>
       <td>月份的数字</td>
      </tr>

      <tr>
       <td><em>s</em></td>
       <td>秒数</td>
      </tr>

      <tr>
       <td><em>t</em></td>
       <td>本月的总天数</td>
      </tr>

      <tr>
       <td><em>U</em></td>
       <td>自 Unix 纪元（January 1 1970 00:00:00
       GMT）起的秒数——这和 <span class="function"><a href="function.time.html" class="function">time()</a></span> 作用相同</td>
      </tr>

      <tr>
       <td><em>w</em></td>
       <td>星期中的第几天（星期天是 <em>0</em>）</td>
      </tr>

      <tr>
       <td><em>W</em></td>
       <td>ISO-8601 格式年份中的第几个星期，每星期从星期一开始</td>
      </tr>

      <tr>
       <td><em>y</em></td>
       <td>年份（1 或 2 位数字——见下面说明）</td>
      </tr>

      <tr>
       <td><em>Y</em></td>
       <td>年份（4 位数字）</td>
      </tr>

      <tr>
       <td><em>z</em></td>
       <td>年份中的第几天</td>
      </tr>

      <tr>
       <td><em>Z</em></td>
       <td>以秒为单位的时区偏移量</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    因为 <span class="function"><strong>idate()</strong></span> 总是返回
    <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>，不能以“0”开头，因此 <span class="function"><strong>idate()</strong></span>
    可能会返回比用户期望中要少的数字。见下面例子：
   </p>
  </p></blockquote>
  <p class="para">
   <div class="informalexample">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$timestamp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">'1st&nbsp;January&nbsp;2004'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//1072915200<br /><br />//&nbsp;下面以两位数字格式显示年份，但是因为<br />//&nbsp;以“0”打头，因此只会显示“4”<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">idate</span><span style="color: #007700">(</span><span style="color: #DD0000">'y'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$timestamp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   参见 <span class="function"><a href="function.date.html" class="function">date()</a></span> 和
   <span class="function"><a href="function.time.html" class="function">time()</a></span>。
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.gmstrftime.html">gmstrftime</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.localtime.html">localtime</a></div>
 <div class="up"><a href="ref.datetime.html">Date/Time 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
